<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      (function () {
        //flat二维数组变成一维数组 一个参数 代表深度
        let arr = [1, 2, 3, 4, [5, 6]];
        console.log(arr.flat(2)); // [1, 2, 3, 4, 5, 6]

        // flatMap() 方法首先使用映射函数映射每个元素，然后将结果压缩成一个新数组
        let arr2 = [1, 2, 3, 4, 5];
        const result = arr2.flatMap((item) => [item * 10]);
        console.log(result); //[10, 20, 30, 40, 50]
      })();
    </script>
  </body>
</html>
